###
 # @Company: TWL
 # @Author: xue jian
 # @Email: xuejian@kanzhun.com
 # @Date: 2020-04-07 10:25:08
 ###
#!/bin/bash
# nohup sh ori_data.sh > ori_result 2>&1 &
train_table=arc.bossrec_train_rtf_all
# train_table=arc_six_dev.bossrec_train

gen_origen_data_file() {
    day=$1
    outpath=/data1/xuejian/sync/offline_train/cp_active_time/$day
    if [ ! -d $outpath ]; then
        mkdir -p ${outpath}
    fi

    # 0~11
    hive -e "set mapreduce.job.queuename=boss.arc.six.vip;
    select boss_city, boss_position, percentile(cast(geek_min_active_tdiff as int), array(0.05,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.91,0.93,0.95,0.98,0.99,0.995)), percentile(cast(exp_min_active_tdiff as int), array(0.05,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.91,0.93,0.95,0.98,0.99,0.995)) from $train_table where ds = '${day}' and hour(list_time) >= 0 and hour(list_time) < 12 group by boss_city, boss_position;" > $outpath/boss_exposure_geek_actice_time_am

    #12~23
    hive -e "set mapreduce.job.queuename=boss.arc.six.vip;
    select boss_city, boss_position, percentile(cast(geek_min_active_tdiff as int), array(0.05,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.91,0.93,0.95,0.98,0.99,0.995)), percentile(cast(exp_min_active_tdiff as int), array(0.05,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.91,0.93,0.95,0.98,0.99,0.995)) from $train_table where ds = '${day}' and hour(list_time) > 11 and hour(list_time) <= 23 group by boss_city, boss_position;" > $outpath/boss_exposure_geek_actice_time_pm
}

main() {
    datebeg=$1
    dateend=$2
    beg_s=`date -d "$datebeg" +%s`
    end_s=`date -d "$dateend" +%s`
    while [ "$beg_s" -le "$end_s" ]
    do
        tmp=`date -d @$beg_s +"%Y-%m-%d"`
        echo $tmp
        gen_origen_data_file $tmp
        beg_s=$((beg_s+86400))
    done
}

main 2020-08-24 2020-08-30



# =========================last edit file content==========================
# dates=("2020-07-10" "2020-07-11" "2020-06-13" "2020-06-14" "2020-06-15" "2020-06-16" "2020-06-17")
# #geek表 arc.geekrec_train_rtf_all
# for day in ${dates[*]}
# do
#     outpath=/data1/xuejian/sync/offline_train/cp_active_time/$day
#     if [ ! -d $outpath ]; then
#         mkdir -p ${outpath}
#     fi

#     #hive -e "set mapreduce.job.queuename=boss.arc.six.vip;
#     #select boss_city, boss_position, percentile(cast(geek_min_active_tdiff as int), array(0.05,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.95,0.98)), percentile(cast(exp_min_active_tdiff as int), array(0.05,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.95,0.98)) from arc_six_dev.bossrec_train where ds = '${day}' group by boss_city, boss_position;" > $outpath/boss_exposure_geek_actice_time_all

#     # 0~11
#     hive -e "set mapreduce.job.queuename=boss.arc.six.vip;
#     select boss_city, boss_position, percentile(cast(geek_min_active_tdiff as int), array(0.05,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.95,0.98)), percentile(cast(exp_min_active_tdiff as int), array(0.05,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.95,0.98)) from arc_six_dev.bossrec_train where ds = '${day}' and hour(list_time) >= 0 and hour(list_time) < 12 group by boss_city, boss_position;" > $outpath/boss_exposure_geek_actice_time_am

#     #12~23
#     hive -e "set mapreduce.job.queuename=boss.arc.six.vip;
#     select boss_city, boss_position, percentile(cast(geek_min_active_tdiff as int), array(0.05,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.95,0.98)), percentile(cast(exp_min_active_tdiff as int), array(0.05,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.95,0.98)) from arc_six_dev.bossrec_train where ds = '${day}' and hour(list_time) > 11 and hour(list_time) <= 23 group by boss_city, boss_position;" > $outpath/boss_exposure_geek_actice_time_pm
# done